package com.gzy.xuexiziliao.controller;


import com.gzy.xuexiziliao.common.result.PageResult;
import com.gzy.xuexiziliao.common.result.Result;
import com.gzy.xuexiziliao.pojo.entity.Review;
import com.gzy.xuexiziliao.service.ReviewService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 反馈与评论控制类
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/review")
public class ReviewController {

    private final ReviewService reviewService;
    //新增反馈与评论
    @PostMapping
    public Result addReview(@RequestBody Review review){
        log.info("新增反馈与评论");
        reviewService.addreview(review);
        return Result.success("新增成功");
    }
    //查看反馈与评论
    @GetMapping("/{id}")
    public Result getReview(@PathVariable Integer reviewId){
        log.info("查看反馈与评论");
        Review review = reviewService.getReview(reviewId);
        return Result.success(review);
    }
    //后台查看反馈
    @GetMapping("/list")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String name, Short gender,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        log.info("分页查询参数：{},{},{},{},{},{}",page,pageSize,name,gender,begin,end);
        PageResult pageResult=reviewService.page(page,pageSize,name,gender,begin,end);
        return Result.success(pageResult);
    }
}
